<template>
	<div class="abnormal-device">
		<div>
			<label>{{$t('route.Device')}}</label>
			<div></div>
			<button><img /><label>{{$t('route.Abnormal_device')}}</label></button>
		</div>

		<div>
			<div>

				<el-select @change='selectChange1' style="margin-left: 10px;" v-model="query.kind" :placeholder="$t('route.Please_select_the_type')">
					<el-option v-for="item in kindList" :key="item" :label="item" :value="item">
					</el-option>
				</el-select>

				<div class="div-handle-right">
					<el-button @click="searchClick">{{$t('route.search')}}</el-button>
					<input v-model="query.search" :placeholder="$t('route.Head_Model')" />
				</div>
			</div>

			<el-table class="table" :data="deviceList" style="width: 100%">
				<el-table-column :label="$t('route.error_state')">
					<template #default="scope">
						{{formatState(scope.row.state)}}
					</template>
				</el-table-column>
				<el-table-column prop="kind" :label="$t('route.kind')" />
				<el-table-column prop="noseCode" :label="$t('route.Head_Model')" />
				<el-table-column :label="$t('route.location')" width="130">
					<template #default="scope">
						{{scope.row.workshop?scope.row.workshop:scope.row.store}}
					</template>
				</el-table-column>
				<el-table-column :label="$t('route.operate')">
					<template #default="scope">
						<el-button type="text" @click='jumpPage(0,scope.row)'>{{$t('route.maintenance_record')}}</el-button>
					</template>
				</el-table-column>
			</el-table>
			<div class="pagination">
				<el-pagination style="float: right;" background @current-change="handlePageChange" :current-page="query.pageNum"
					:page-size="query.pageSize" layout="total, prev, pager, next" :total="query.total"></el-pagination>
			</div>

		</div>


	</div>
</template>

<script>
	import http from "../../js/http/http.js";
	import api from "../../js/http/api.js";
	import CommonUtils from "../../js/common/common-utils.js";
	import Constant from '../../js/common/constant.js'
	import i18n from '../../i18n/index';
	export default {
		data() {
			return {
				query: {
					kind: i18n.global.t('route.All_categories'),
					pageNum: 1,
					pageSize: 10,
					total: 0,
					search: null,
				},
				deviceList: [],
				kindList: [i18n.global.t('route.All_categories'), ...Constant.DEVICE_KIND],
			};
		},
		methods: {
			jumpPage(type, param1) {
				if (type == 0) {
					this.$router.push({
						name: "repair-record",
						params: {
							noseCode: param1.noseCode
						}
					});
				}
			},
			selectChange1() {
				this.query.search = null;
				this.query.pageNum = 1;
				this.getAbnormalDeviceList();
			},

			handlePageChange(pageNum) {
				this.query.pageNum = pageNum;
				this.getAbnormalDeviceList();
			},
			searchClick() {
				this.query.pageNum = 1;
				this.getAbnormalDeviceList();
			},
			getAbnormalDeviceList() {
				http.post(api.GET_ABNORMAL_DEVICE_LIST, {
					adminId: this.$store.state.user.id,
					kind: this.query.kind == i18n.global.t('route.All_categories') ? null : this.query.kind,
					search: this.query.search,
					pageNum: this.query.pageNum,
					pageSize: this.query.pageSize
				}, data => {
					this.deviceList = data.data.deviceList;
					this.query.total = data.data.total;
				})
			},
			formatState(state) { //0:没有异常 1:普通维修 2:大修 3报废 4:异常报警
				if (state == 0) {
					return i18n.global.t('route.normal');
				} else if (state == 1) {
					return i18n.global.t('route.General_maintenance');
				} else if (state == 2) {
					return  i18n.global.t('route.Overhaul');
				} else if (state == 3) {
					return i18n.global.t('route.Scrap');
				} else if (state == 4) {
					return i18n.global.t('route.Abnormal_alarm');
				}
			},

		},
		created() {
			this.user = this.$store.state.user;
			this.getAbnormalDeviceList();
		},

		mounted() {

		}
	};
</script>
<style lang="scss" scoped>
	.abnormal-device {
		color: #444444;
		font-size: 18px;
		padding-right: 20px;
		height: calc(100vh - 100px);
		// overflow: scroll;
		scrollbar-width: none;
		/* firefox */
		-ms-overflow-style: none;
		/* IE 10+ */
		overflow-x: hidden;
		overflow-y: auto;

		>div:nth-of-type(1) {
			display: flex;
			flex-direction: row;
			align-items: center;
			margin-top: 20px;
			background-color: #ffffff;
			padding: 20px;
			border-radius: 5px;

			>label:nth-of-type(1) {
				font-weight: 600;
			}

			>div:nth-of-type(1) {
				width: 1px;
				background-color: #cccccc;
				height: 15px;
				margin: 0px 20px;
			}

			>button:nth-of-type(1) {
				background-image: url(../../assets/img/customer-1.png);
				background-repeat: no-repeat;
				background-size: 100% 100%;
				padding: 5px 10px;
				border: 0px;
				display: flex;
				color: #ffffff;
				flex-direction: row;
				align-items: center;
				font-weight: 800;

				>img {
					margin-right: 7px;
					width: 15px;
					height: 15px;
					content: url(../../assets/img/customer-2.png);
				}
			}
		}

		>div:nth-of-type(2) {
			display: flex;
			flex-direction: column;
			margin-top: 20px;
			background-color: #ffffff;
			padding: 20px;
			border-radius: 5px;


			>div:nth-of-type(1) {
				display: flex;
				flex-direction: row;
				align-items: center;

				.div-handle-right {
					flex: 1;
					flex-direction: row-reverse;
					text-align: right;
					display: flex;
					align-items: center;

					>input:nth-of-type(1) {
						border: 1px solid #eeeeee;
						font-size: 15px;
						width: 200px;
						padding: 5px 8px;
						outline: none;
					}

					>button {
						color: #A866FF;
						margin-left: 10px;
						padding: 4px 20px;
					}
				}
			}

			.table {
				margin-top: 20px;
			}

		}

		.select {
			width: 120px;
			margin-top: 10px;
		}

		.echart {
			height: 150px;
			width: 100%;
		}

		.input {
			width: 250px;
		}


	}
</style>
